/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [GobangButton.java]
 * Creation Date        [22-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_03_game.gobang.version_5;

import java.awt.event.MouseEvent;

import javax.swing.JOptionPane;

/**
 * 五子棋按钮
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class GobangButton {

	private final GobangFrame frame;

	public GobangButton(GobangFrame frame) {
		this.frame = frame;
	}

	/**
	 * 开始游戏
	 * 
	 * @param event
	 */
	public void startGame(MouseEvent event) {
		if (event.getX() > 400 && event.getX() < 470 && event.getY() > 80
				&& event.getY() < 100) {
			int result = JOptionPane.showConfirmDialog(frame, "是否重新开始游戏");
			if (result == 0) {
				frame.allChess = new int[19][19];
				frame.isBlack = true;
				frame.isContinue = true;
				frame.repaint();
				JOptionPane.showMessageDialog(frame, "游戏开始");
			}
		}
	}

	/**
	 * 游戏信息
	 * 
	 * @param event
	 */
	public void gameInfo(MouseEvent event) {
		if (event.getX() > 400 && event.getX() < 470 && event.getY() > 180
				&& event.getY() < 200) {
			JOptionPane.showMessageDialog(frame, "五子棋游戏, 黑白双方轮流下棋, 一方连到五子游戏结束");
		}
	}

	/**
	 * "认输"按钮
	 * 
	 * @param event
	 */
	public void giveUp(MouseEvent event) {
		if (event.getX() > 400 && event.getX() < 470 && event.getY() > 280
				&& event.getY() < 300) {
			int result = JOptionPane.showConfirmDialog(frame, "您真的要认输吗?");
			if (result == 0) {
				if (frame.isBlack) {
					frame.message = "黑方认输";
					JOptionPane.showMessageDialog(frame, frame.message);
				} else {
					frame.message = "白方认输";
					JOptionPane.showMessageDialog(frame, frame.message);
				}
				frame.isContinue = false;
				frame.repaint();
			}
		}
	}

	/**
	 * "关于"按钮
	 * 
	 * @param event
	 */
	public void about(MouseEvent event) {
		if (event.getX() > 400 && event.getX() < 470 && event.getY() > 330
				&& event.getY() < 350) {
			JOptionPane.showMessageDialog(frame, "Copy Right by Sean Yang");
		}
	}

	/**
	 * "退出"按钮
	 * 
	 * @param event
	 */
	public void quit(MouseEvent event) {
		if (event.getX() > 400 && event.getX() < 470 && event.getY() > 380
				&& event.getY() < 400) {
			int result = JOptionPane.showConfirmDialog(frame, "您真的想退出吗? ");
			if (result == 0) {
				System.exit(0);
			}
		}
	}
}
